<template>
  <div>
    <div class="container">
      <div class="flex">
        <div
          style="width: 370px;height: 422px;background: #FFFFFF;box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);"
        >
          <div class="nav flex border_top">
            <div
              v-for="(item, index) in navList"
              :key="index"
              class="flex align-center"
              :class="nav_act == index ? 'active' : ''"
              @click="navclcik(index, item.path)"
            >{{ item.text }}</div>
          </div>
        </div>

        <div
          style=" width: 813px;height: 422px; background: #FFFFFF;box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);"
          class="ml-2"
        >
          <div class="nan flex border_top">
            <div
              v-for="(item, index) in nanList"
              :key="index"
              class="flex align-center"
              :class="nav_act == index ? 'active' : ''"
              @click="navclcik(index, item.path)"
            >{{ item.gs }}</div>
          </div>

          <div style="width:810px;height:370px;border:1px solid #E6E6E6;" class="mt-1">
            <div style="text-align:center" class="cyb flex">
              <span @click="cybc">创业板</span>
              <span @click="zxb">中小板</span>
            </div>
            <el-table
              v-if="cyb == 0"
              :data="tableData"
              style="width:810px;"
              :row-class-name="tableRowClassName"
            >
              <el-table-column prop="dm" label="代码" width="200"></el-table-column>
              <el-table-column prop="name" label="名称" width="200"></el-table-column>
              <el-table-column prop="zdf" label="涨跌幅" width="200"></el-table-column>
              <el-table-column prop="zgj" label="最高价"></el-table-column>
            </el-table>
            <el-table
              v-if="cyb == 1"
              :data="zxbList"
              style="width:810px;"
              :row-class-name="tableRowClassName"
            >
              <el-table-column prop="dm" label="代码" width="200"></el-table-column>
              <el-table-column prop="name" label="名称" width="200"></el-table-column>
              <el-table-column prop="zdf" label="涨跌幅" width="200"></el-table-column>
              <el-table-column prop="zgj" label="最高价"></el-table-column>
            </el-table>
          </div>
        </div>
      </div>

      <div class="mt-2">
        <img src="../../../assets/img/hscylsfz.png" alt />
      </div>
    </div>
    <div class="flex justify-between mt-2">
      <Leader></Leader>
      <Online></Online>
    </div>
  </div>
</template>

<script>
import Leader from "../leaderSpeech/leader";
import Online from "../leaderSpeech/online";
import newApi from "@/api/newCenter/new";
export default {
  name: "indexChart",
  components: {
    Leader,
    Online,
  },
  data() {
    return {
      navList: [
        {
          path: "/",
          text: "大盘指数",
        },
      ],
      nav_act: 0,
      nanList: [
        {
          path: "/",
          gs: "股市行情",
        },
      ],
      tableData: [],
      cyb: "",
      zxbList:[],
    };
  },
  mounted() {
    this.getgs();
  },
  methods: {
    navclcik(index, path) {
      this.nav_act = index;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    getgs() {
      newApi
        .getgshx({})
        .then((res) => {
          this.tableData = res.data.data.cybz;
          console.log(this.tableData);
        })
        .catch(() => {});
    },
    getzxb() {
      newApi
        .getgshx({})
        .then((res) => {
          this.zxbList = res.data.data.zxb;
          console.log(this.zxbList);
        })
        .catch(() => {});
    },
    cybc() {
      this.cyb == 0;
    },
    zxb(){
      this.cyb == 1;
    }
  },
};
</script>

<style lang="stylus" scoped>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.container {
  margin-top: 15px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}

.nav {
  position: relative;
}

.nav>div {
  height: 40px;
  font-size: 16px;
  font-weight: 400;
  color: #BF242A;
  padding: 0 20px;
  cursor: pointer;
}

.nav>div.active {
  color: #ffffff;
  border-color: #ffffff;
  background: #EB424C;
  // border-image: -webkit-linear-gradient(to right, #00036B, #409EFF) 30 30;
  // border-image: -moz-linear-gradient(to right, #00036B, #409EFF) 30 30;
  // border-image: linear-gradient(to right, #00036B, #409EFF) 30 30;
}

.nan {
  position: relative;
}

.nan>div {
  height: 40px;
  font-size: 16px;
  font-weight: 400;
  color: #BF242A;
  padding: 0 20px;
  cursor: pointer;
}

.nan>div.active {
  color: #ffffff;
  border-color: #ffffff;
  background: #EB424C;
  // border-image: -webkit-linear-gradient(to right, #00036B, #409EFF) 30 30;
  // border-image: -moz-linear-gradient(to right, #00036B, #409EFF) 30 30;
  // border-image: linear-gradient(to right, #00036B, #409EFF) 30 30;
}

.cyb {
  span {
    display: block;
    width: 50%;
    line-height: 40px;
    background: #fff;
    cursor: pointer;
  }

  span:hover {
    background: #E6E6E6;
  }
}
</style>
